<?php


namespace app\common\model;


class CartModel extends CommonModel
{
    protected $name = 'cart';

    public function productInfo(): \think\model\relation\hasOne
    {
        return $this->hasOne(ProductModel::class, 'id', 'product_id');
    }

    public function productSkuInfo(): \think\model\relation\hasOne
    {
        return $this->hasOne(ProductSkuModel::class, 'id', 'product_sku_id');
    }

    public function getUserCartList($where = []): \think\Collection
    {
        return $this->with([
            'productInfo',
            'productSkuInfo',
        ])->order([
            //            'case_number'        => 'desc',
            'create_time' => 'desc',
        ])->where($where)->select();
    }

    public function getUserCartByIds($where = []): \think\Collection
    {
        return $this->with([
            'productInfo',
            'productSkuInfo',
        ])->order([
            //            'case_number'        => 'desc',
            'create_time' => 'desc',
        ])->where($where)->select();

    }
}